package com.xu.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xu.mapper.CourseMapper;
import com.xu.pojo.Course;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class CourseServiceImpl implements CourseService{

    @Autowired
    private CourseMapper courseMapper;

    @Override
    public List<Course> queryCourse() {
        return courseMapper.queryCourse();
    }

    @Override
    public PageInfo<Course> queryCoursePaging(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Course> lists = courseMapper.queryCourse();
        PageInfo<Course> pageInfo = new PageInfo<Course>(lists);
        return pageInfo;
    }

    @Override
    public List<Course> queryCourseIf(String queryCondition, int collegeId) {
        return courseMapper.queryCourseIfIdNameCollege(queryCondition,collegeId);
    }

    @Override
    public PageInfo<Course> queryCourseIfPaging(String queryCondition, int collegeId, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Course> lists = courseMapper.queryCourseIfIdNameCollege(queryCondition, collegeId);
        PageInfo<Course> pageInfo = new PageInfo<Course>(lists);
        return pageInfo;
    }

    @Override
    public PageInfo<Course> queryCourseByTeacherIdPaging(int teacherId, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Course> lists = courseMapper.queryCourseByTeacherId(teacherId);
        PageInfo<Course> pageInfo = new PageInfo<Course>(lists);
        return pageInfo;
    }

    @Override
    public Boolean checkCourse(int teacherId, int courseId) {
        if (courseMapper.queryCourseNumByCourseIdTeacherId(courseId,teacherId)>0)
            return true;
        else
            return false;
    }


    @Override
    public int deleteCourse(int courseId) {
        return courseMapper.deleteCourseByCourseId(courseId);
    }

    @Override
    public Course queryCourseById(int courseId) {
        return courseMapper.queryCourseById(courseId);
    }

    @Override
    public int updateCourse(Course course) {
        return courseMapper.updateCourse(course);
    }

    @Override
    public int addCourse(Course course) {
        return courseMapper.addCourse(course);
    }
}
